package Threads.ReentrantLock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;



//用这个debug了aqs的源码，实在是好复杂
public class interruputTest_2 {
    public static void main(String[] args) throws InterruptedException {
        /*Thread t=new Thread(()->{
            System.out.println("hahha");
            LockSupport.park();
            System.out.println("xiexie");
            System.out.println(Thread.interrupted()+"--------t");
            Thread.currentThread().interrupt();
            System.out.println("HAHAHAH");
        });
        t.start();

        Thread.sleep(2000);
        t.interrupt();
        Thread.sleep(1000);
        System.out.println(t.isInterrupted());*/
        ReentrantLock lock=new ReentrantLock();
        Condition condition=lock.newCondition();
        Thread t= new Thread(()->{
            try {
                lock.lock();
                condition.awaitNanos(TimeUnit.SECONDS.toNanos(2));
                System.out.println("nihao!");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        });
        t.start();
        /*new Thread(()->{
            lock.lock();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        },"t2").start();
        Thread.sleep(1000);
        /*lock.lock();
        condition.signal();
        lock.unlock();
        //t.interrupt();*/

    }
}
